package fr.afcepf.atod20.model.util;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.ResourceBundle;
import java.util.logging.Logger;

import javax.sql.DataSource;

public class SimpleDataSource implements DataSource {

	public Connection getConnection() throws SQLException {
		
		Connection cnx = null;
		
		// va chercher un fichier "db.properties" à partir
		// de la racine du classpath de l'application
		try {
			ResourceBundle resources = ResourceBundle.getBundle("db");
			
			// permet d'eviter un nom de bdd en dur
			Class.forName(resources.getString("driver"));
			
			cnx = DriverManager.getConnection(
					resources.getString("url"),
					resources.getString("login"),
					resources.getString("password")
					);
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
				
		return cnx;
		
	}
	
	public PrintWriter getLogWriter() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public void setLogWriter(PrintWriter out) throws SQLException {
		// TODO Auto-generated method stub

	}

	public void setLoginTimeout(int seconds) throws SQLException {
		// TODO Auto-generated method stub

	}

	public int getLoginTimeout() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public Logger getParentLogger() throws SQLFeatureNotSupportedException {
		// TODO Auto-generated method stub
		return null;
	}

	public <T> T unwrap(Class<T> iface) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean isWrapperFor(Class<?> iface) throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}


	public Connection getConnection(String username, String password)
			throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

}
